<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>MouseGetPos</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>MouseGetPos</h1>

<p>Retrieves the current position of the mouse cursor, and optionally which window and control it is hovering over.</p>

<pre class="Syntax">MouseGetPos, [OutputVarX, OutputVarY, OutputVarWin, OutputVarControl, 1|2|3]</pre>
<h3>Parameters</h3>
<dl>

  <dt>OutputVarX/Y</dt>
  <dd><p>The names of the variables in which to store the X and Y coordinates. The retrieved coordinates are relative to the active window unless <a href="CoordMode.htm">CoordMode</a> was used to change to screen coordinates.</p>
    </dd>

  <dt>OutputVarWin</dt>
  <dd><p>This optional parameter is the name of the variable in which to store the <a href="WinGet.htm">unique ID number</a> of the window under the mouse cursor. If the window cannot be determined, this variable  will be made blank.</p>
      <p>The window does not have to be active to be detected. Hidden windows cannot be detected.</p></dd>

  <dt>OutputVarControl</dt>
  <dd><p>This optional parameter is the name of the variable in which to store the name (ClassNN) of the control under the mouse cursor.  If the control cannot be determined, this variable  will be made blank.</p>
      <p>The names of controls should always match those shown by the version of Window Spy distributed with v1.0.14+ (but not necessarily older versions of Window Spy). However, unlike Window Spy, the window under the mouse cursor does not have to be active for a control to be detected.</p></dd>

  <dt>1|2|3</dt>
  <dd><p>If omitted, it defaults to 0. Otherwise, specify one of the following digits:</p>
    <p><strong>1</strong>: Uses a simpler method to determine <em>OutputVarControl</em>. This method correctly retrieves the active/topmost child window of an Multiple Document Interface (MDI) application such as SysEdit or TextPad. However, it is less accurate for other purposes such as detecting controls inside a GroupBox control.</p>
    <p><strong>2</strong> <span class="ver">[v1.0.43.06+]:</span> Stores the <a href="ControlGet.htm#Hwnd">control's HWND</a> in <em>OutputVarControl</em> rather than the control's ClassNN.</p>
    <p><strong>3</strong> <span class="ver">[v1.0.43.06+]:</span> A combination of 1 and 2 above.</p></dd>

</dl>

<h3>Remarks</h3>
<p>Any of the output variables may be omitted if the corresponding information is not needed.</p>
<h3>Related</h3>
<p><a href="CoordMode.htm">CoordMode</a>, <a href="WinGet.htm">WinGet</a>, <a href="SetDefaultMouseSpeed.htm">SetDefaultMouseSpeed</a>, <a href="Click.htm">Click</a></p>
<h3>Example</h3>
<pre class="NoIndent">MouseGetPos, xpos, ypos 
Msgbox, The cursor is at X%xpos% Y%ypos%. 

<em>; This example allows you to move the mouse around to see
; the title of the window currently under the cursor:</em>
#Persistent
SetTimer, WatchCursor, 100
return

WatchCursor:
MouseGetPos, , , id, control
WinGetTitle, title, ahk_id %id%
WinGetClass, class, ahk_id %id%
ToolTip, ahk_id %id%`nahk_class %class%`n%title%`nControl: %control%
return</pre>

</body>
</html>
